﻿//(function ($) {
//    $.fn.extend({
//        center: function (options) {
//            var options = $.extend({ transition: 0, minX: 0, minY: 0, parentSelector: '' }, options);
//            return this.each(function () {
//                $(this).css('position', 'absolute');
//                //debugger;
//                var top = (_getParentSelector(options).height() - $(this).outerHeight()) / 2 + _getParentSelector(options).scrollTop();
//                var left = (_getParentSelector(options).width() - $(this).outerWidth()) / 2 + _getParentSelector(options).scrollLeft();
//                $(this).animate({
//                    top: (top > options.minY ? top : options.minY) + 'px',
//                    left: (left > options.minX ? left : options.minX) + 'px'
//                }, options.transition);

//                $(this).effect('highlight', {}, 500, null);
//                return $(this);
//            });

//            function _getParentSelector($settings) {
//                if ($settings.parentSelector) {
//                    if ($settings.parentSelector == '') {
//                        return $(window);
//                    }
//                    else {
//                        return $($settings.WindowParentSelector);
//                    }
//                }
//                else {
//                    return $(window);
//                }
//            }
//        }
//    });

//})(jQuery);

//(function ($) {
//    $.fn.extend({
//        center: function (options) {
//            var options = $.extend({ transition: 0, minX: 0, minY: 0, parentSelector: '', absolute: true }, options);
//            return this.each(function () {
//                var t = jQuery(this);
//                debugger;
//                t.css({
//                    position: options.absolute ? 'absolute' : 'fixed',
//                    left: '50%',
//                    top: '50%',
//                    zIndex: '99'
//                }).css({
//                    marginLeft: '-' + (t.outerWidth() / 2) + 'px',
//                    marginTop: '-' + (t.outerHeight() / 2) + 'px'
//                });

//                if (options.absolute) {
//                    t.css({
//                        marginTop: parseInt(t.css('marginTop'), 10) + _getParentSelector(options).scrollTop(),
//                        marginLeft: parseInt(t.css('marginLeft'), 10) + _getParentSelector(options).scrollLeft()
//                    });
//                }
//            });

//            function _getParentSelector($settings) {
//                if ($settings.parentSelector) {
//                    if ($settings.parentSelector == '') {
//                        return $(window);
//                    }
//                    else {
//                        return $($settings.WindowParentSelector);
//                    }
//                }
//                else {
//                    return $(window);
//                }
//            }
//        }
//    });

//})(jQuery);

(function ($) {
    $.fn.extend({
        center: function (options) {
            var options = $.extend({ // Default values
                parentSelector: '',
                inside: null, // element, center into window
                transition: 0, // millisecond, transition time
                minX: 0, // pixel, minimum left element value
                minY: 0, // pixel, minimum top element value
                vertical: true, // booleen, center vertical
                withScrolling: true, // booleen, take care of element inside scrollTop when minX < 0 and window is small or when window is big
                horizontal: true // booleen, center horizontal
            }, options);
            options.inside = _getParentSelector(options);
            return this.each(function () {
                var props = { position: 'absolute' };
                if (options.vertical) {
                    //var top = (options.inside.height() - $(this).outerHeight()) / 2;
                    var top = options.inside.height() / 2;
                    if (options.withScrolling) top += options.inside.scrollTop() || 0;
                    top = (top > options.minY ? top : options.minY);
                    //top -= $(this).height() / 2;
                    top -= $(this).getHiddenDimensions().height / 2;
                    $.extend(props, { top: top + 'px' });
                }
                if (options.horizontal) {
                    //var left = (options.inside.width() - $(this).outerWidth()) / 2;
                    var left = options.inside.width() / 2;
                    if (options.withScrolling) left += options.inside.scrollLeft() || 0;
                    left = (left > options.minX ? left : options.minX);
                    //left -= $(this).width() / 2;
                    left -= $(this).getHiddenDimensions().width / 2;
                    $.extend(props, { left: left + 'px' });
                }
                if (options.transition > 0) $(this).animate(props, options.transition);
                else $(this).css(props);
                return $(this);
            });

            function _getParentSelector($settings) {
                return $(window);
                if ($settings.parentSelector) {
                    if ($settings.parentSelector == '') {
                        return $(window);
                    }
                    else {
                        return $($settings.parentSelector);
                    }
                }
                else {
                    return $(window);
                }
            }
        }
    });
})(jQuery);


(function ($) {
    $.fn.getHiddenDimensions = function (includeMargin) {
        var $item = this,
			props = { position: 'absolute', visibility: 'hidden', display: 'block' },
			dim = { width: 0, height: 0, innerWidth: 0, innerHeight: 0, outerWidth: 0, outerHeight: 0 },
			$hiddenParents = $item.parents().andSelf().not(':visible'),
			includeMargin = (includeMargin == null) ? false : includeMargin;

        var oldProps = [];
        $hiddenParents.each(function () {
            var old = {};

            for (var name in props) {
                old[name] = this.style[name];
                this.style[name] = props[name];
            }

            oldProps.push(old);
        });

        dim.width = $item.width();
        dim.outerWidth = $item.outerWidth(includeMargin);
        dim.innerWidth = $item.innerWidth();
        dim.height = $item.height();
        dim.innerHeight = $item.innerHeight();
        dim.outerHeight = $item.outerHeight(includeMargin);

        $hiddenParents.each(function (i) {
            var old = oldProps[i];
            for (var name in props) {
                this.style[name] = old[name];
            }
        });

        return dim;
    }
} (jQuery));

var urlParam =
{
    getParam: function (paramName) {
        var results = new RegExp('[\\?&]' + paramName + '=([^&#]*)').exec(window.location.href);
        if (!results) { return 0; }
        return results[1] || 0;
    },

    getUrlParam: function (url, paramName) {
        var results = new RegExp('[\\?&]' + paramName + '=([^&#]*)').exec(url);
        if (!results) { return 0; }
        return results[1] || 0;
    },

    replaceUrl: function (url, paramName, paramValue) {
        return null;
        //        var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
        //        if (!results) { return 0; }
        //        return results[1] || 0;
    }
};

(function ($) {
    $.fn.extend({
        maxZIndex: function (opt) {
            /// <summary>
            /// Returns the max zOrder in the document (no parameter)
            /// Sets max zOrder by passing a non-zero number
            /// which gets added to the highest zOrder.
            /// </summary>    
            /// <param name="opt" type="object">
            /// inc: increment value, 
            /// group: selector for zIndex elements to find max for
            /// </param>
            /// <returns type="jQuery" />
            var def = { inc: 10, group: "*" };
            $.extend(def, opt);
            var zmax = 0;
            $(def.group).each(function () {
                var cur = parseInt($(this).css('z-index'));
                zmax = cur > zmax ? cur : zmax;
            });
            if (!this.jquery)
                return zmax;

            return this.each(function () {
                zmax += def.inc;
                $(this).css("z-index", zmax);
            });
        }
    });
})(jQuery);

(function ($) {
    $.formatBytes = function (size, precision) {
        if (typeof size == "undefined" || isNaN(parseInt(size))) {
            return size;
        }
        if (typeof precision == "undefined") {
            precision = 2;
        }

        var base = Math.log(size) / Math.log(1024);
        var suffixes = new Array('bytes', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB');
        return Math.round(Math.pow(1024, base - Math.floor(base)), precision) + ' ' + suffixes[Math.floor(base)];
    };
}) (jQuery);




//$(document).ready(function () {
//    $(".shortDateFormat").each(function (idx, elem) {
//        if ($(elem).is(":input")) {
//            $(elem).val($.format.date($(elem).val(), 'dd/MM/yyyy'));
//        } else {
//            $(elem).text($.format.date($(elem).text(), 'dd/MM/yyyy'));
//        }
//    });
//    $(".longDateFormat").each(function (idx, elem) {
//        if ($(elem).is(":input")) {
//            $(elem).val($.format.date($(elem).val(), 'dd/MM/yyyy hh:mm:ss'));
//        } else {
//            $(elem).text($.format.date($(elem).text(), 'dd/MM/yyyy hh:mm:ss'));
//        }
//    });
//});